﻿using MediatR;
using WarehouseManagement.Application.Command.WarehouseCommand;
using WarehouseManagement.Domain.DTO.Warehouse;
using WarehouseManagement.Domain.DTO.WarehouseType;
using WarehouseManagement.Infrstructre.Imp;
using WarehouseManagement.Infrstructre.Interface;

namespace WarehouseManagement.Application.CommandHandler.WarehouseCommandHandler
{
    /// <summary>
    /// 仓库信息反填
    /// </summary>
    public class WarehouseFanCommandHandler : IRequestHandler<WarehouseFanCommand, UpdFanWarehouseDTO>
    {
        private readonly IWarehouseRepository _warehouseRep;
        public WarehouseFanCommandHandler(IWarehouseRepository warehouseRep)
        {
            _warehouseRep = warehouseRep;
        }

        public async Task<UpdFanWarehouseDTO> Handle(WarehouseFanCommand request, CancellationToken cancellationToken)
        {
            var result = (await _warehouseRep.GetAll())
               .Where(x => x.WarehouseId == request.WarehouseId)
               .ToList();
            var dto = result.Select(x => new UpdFanWarehouseDTO
            {
                WarehouseId=x.WarehouseId,
                WNumber=x.WNumber,
                WName=x.WName,
                WType=x.WType,
                WAddress=x.WAddress,
                WarehouseRemark = x.WarehouseRemark,
                DelTime = x.DelTime,
                DelName = x.DelName,
                Office_Id = x.Office_Id,
                User_Id = x.User_Id,
                UpdName = x.UpdName,
                UpdTime = x.UpdTime

            }).FirstOrDefault();
            return dto;
        }
    }
}
